package com.lxw.manage.course.controller;

import com.lxw.api.course.CourseControllerApi;
import com.lxw.framework.domain.course.CoursePic;
import com.lxw.framework.domain.course.Teachplan;
import com.lxw.framework.domain.course.TeachplanMedia;
import com.lxw.framework.domain.course.ext.CourseView;
import com.lxw.framework.domain.course.ext.TeachplanNode;
import com.lxw.framework.domain.course.request.CourseListRequest;
import com.lxw.framework.domain.course.response.CoursePublishResult;
import com.lxw.framework.model.response.QueryResponseResult;
import com.lxw.framework.model.response.ResponseResult;
import com.lxw.manage.course.service.CourseService;
import com.lxw.manage.course.service.TeachPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 *
 */
@RestController
@RequestMapping("/course")
public class CourseController implements CourseControllerApi {

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeachPlanService teachPlanService;

    @Override
    @GetMapping("/teachplan/list/{courseId}")
    public TeachplanNode findTeachPlanByCourseId(@PathVariable("courseId") String courseId) {
        return teachPlanService.findTeanplansByCourseId(courseId);
    }

    @Override
    @PostMapping("/teachplan/add")
    public ResponseResult addTeachPlan(@RequestBody Teachplan teachplan) {

        return teachPlanService.addTeachPlan(teachplan);
    }

    @Override
    @PostMapping("/coursepic/add")
    public ResponseResult addCoursePic(@RequestParam("courseId") String courseId,@RequestParam("pic") String fileId) {
        return courseService.addCoursePic(courseId,fileId);

    }

    @GetMapping("/coursepic/list/{courseId}")
    @Override
    public CoursePic findCoursePicByCourseId(@PathVariable("courseId") String courseId) {
        return courseService.findCoursePicByCourseId(courseId);
    }

    @Override
    @DeleteMapping("/coursepic/delete")
    public ResponseResult deleteCoursePicByCourseId(@RequestParam("courseId") String courseId) {
        return courseService.deleteCoursePicById(courseId);
    }

    @Override
    @GetMapping("/courseview/{id}")
    public CourseView courseview(@PathVariable("id") String id) {
        return courseService.findCourseViewById(id);
    }

    @Override
    @PostMapping("/preview/{id}")
    public CoursePublishResult preview(@PathVariable("id") String id) {
        return courseService.preview(id);
    }

    @Override
    @PostMapping("/publish/{id}")
    public CoursePublishResult publish(@PathVariable("id") String id) {
        return courseService.publish(id);
    }

    @Override
    @PostMapping("/savemedia")
    public ResponseResult saveTeachMedia(@RequestBody TeachplanMedia teachplanMedia) {
        return courseService.saveTeachMedia(teachplanMedia);
    }


}
